/**
 * Created by Delicate on 2017/5/31.
 */
//let layer;
//let ajax;
//let WebUploader;
//require(["jquery","common","layer","ajax","webuploader"],(a,b,c,d,e)=>{
//	WebUploader=e;
//	layer = c
//    init();
//    monitor();
//    service();
//    ajax =d;
//   
//})

$(document).ready(function(){
	init();
    monitor();
    service();
});

function initUploader(uploadBtn){
	var uploader = WebUploader.create({
        auto: true,
        swf:  contextPath+ '/assets/front/web/script/upload/Uploader.swf',
        server: contextPath+'/qiniu/upload',
        pick: {
            id:'#'+uploadBtn
        },
        multiple:false,
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'
        }
    });
    // 当有文件添加进来的时候
    uploader.on( 'fileQueued', function( file ) {
    	var up=$("#"+uploadBtn);
        uploader.makeThumb( file, function( error, src ) {
            if ( error ) {
                $img.replaceWith('<span>不能预览</span>');
                return;
            }
            $("#"+uploadBtn+"_container").html('<div style="text-align:center;vertical-align:middle;color:#DDDDDD">图片文件正在上传中，请稍候...</div>')
        }, "100", "100" );
    });
    
    //文件上传成功处理
    uploader.on( 'uploadSuccess', function( file,resp ) {
    	$("#"+uploadBtn+"_val").val(resp._raw);
    	$("#"+uploadBtn+"_container").html('<div class="u-row-cell-upload-btn-border" style="background: url('+resp._raw+') center/contain no-repeat"></div>')
    });
    
    //文件上传失败处理
    uploader.on( 'uploadError', function( file ) {
    	
    });
    
    // 文件上传过程中创建进度条实时显示。
    uploader.on( 'uploadProgress', function( file, percentage ) {
    });
    return uploader;
}


init = function(){
	initUploader("logo");
	initUploader("license");
	initUploader("idcardFront");
	initUploader("idcardTails");
	initUploader("chargeCard"); 
}
function monitor(){

}
function service(){

}

var successCallBack=function(data){
	if(data.result){
		window.location.href= contextPath+'/passport/authWork'
    }else{
        layer.alert(data.msg)
    }
}

var asubmit=function(){
    var company_name = $("#company_name").val().trim();
    var company_address = $("#company_address").val().trim();
    var company_charge = $("#company_charge").val().trim();
    var company_charge_phone = $("#company_charge_phone").val().trim();
    if(!company_name){
        layer.alert("请输入公司名称");
        return;
    }
    if(!company_address){
        layer.alert("请输入公司地址");
        return;
    }
    if(!company_charge){
        layer.alert("请输入负责人姓名");
        return;
    }
    if(!company_charge_phone){
        layer.alert("请输入负责人手机号");
        return;
    }
    if(!$("#license_val").val()){
        layer.alert("请上传营业执照");
        return;
    }
    if(!$("#idcardFront_val").val()){
        layer.alert("请上传身份证正面");
        return;
    }
    if(!$("#idcardTails_val").val()){
        layer.alert("请上传身份证反面");
        return;
    }
    if(!$("#chargeCard_val").val()){
        layer.alert("请上传负责人名片");
        return;
    }
    //$("#authForm").submit();
    var data = $("#authForm").serialize();
    var ajax = new BackendTool({"data":data,"method":"post","url":contextPath+"/passport/auth"});
    ajax.successCallBack = successCallBack;
    ajax.ajaxRequest();
}